﻿/*http://java-007.javaeye.com/blog/260675*/

//得到每周的第一天(周一)   
function getFirstDateOfWeek(theDate){   
 var firstDateOfWeek;   
 theDate.setDate(theDate.getDate() + 1 - theDate.getDay());    
 firstDateOfWeek = theDate;   
 return firstDateOfWeek;    
}   
//得到每周的最后一天(周日)   
function getLastDateOfWeek(theDate){   
 var lastDateOfWeek;   
 theDate.setDate(theDate.getDate() +7 - theDate.getDay());   
 lastDateOfWeek = theDate;   
 return lastDateOfWeek;    
}   
  
//得到上周的第一天(周一)   
function getPreviousFirstDateOfWeek(theDate){   
 var firstDateOfWeek;   
 theDate.setDate(theDate.getDate() - 6 - theDate.getDay());    
 firstDateOfWeek = theDate;   
 return firstDateOfWeek;    
}   
//得到上周的最后一天(周日)   
function getPreviousLastDateOfWeek(theDate){   
 var lastDateOfWeek;   
 theDate.setDate(theDate.getDate() +7 - theDate.getDay());   
 lastDateOfWeek = theDate;   
 return lastDateOfWeek;    
}  


/*
//取得处理字符串，然后转换成日期类型。   
var   s   =   "2008-02-15";      
s = s+"   00:00:00";   
var   tD   =   new   Date(Date.parse(s.replace(/-/g,   "/")));    

//得到上周的第一天以及最后一天。   
  
var lWeekFirstDay = getPreviousFirstDateOfWeek(tD).toLocaleString();   
var lWeekLastDay = getPreviousLastDateOfWeek(tD).toLocaleString();   
  
var ch2 = MM_dateFormat(lWeekFirstDay,7);   
var ch3 = MM_dateFormat(lWeekLastDay,7);   
  
alert("上周一的时间是:" + ch2);   
alert("上周日的时间是:" + ch3 );   
  
//得到本周的第一天以及最后一天。   
  
var nWeekFirstDay = getFirstDateOfWeek(tD).toLocaleString();   
var nWeekLastDay= getLastDateOfWeek(tD).toLocaleString();   
var ch = MM_dateFormat(nWeekFirstDay,7);   
var ch1 = MM_dateFormat(nWeekLastDay,7);   
alert("本周一的时间是:" + ch);   
alert("本周日的时间是:" + ch1);  */